package com.cy.detectsys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cy.detectsys.entity.NetPop;
import com.cy.detectsys.entity.vo.PopVo;
import com.cy.detectsys.response.PopResponse;
import com.cy.detectsys.service.NetPopService;
import com.cy.detectsys.mapper.NetPopMapper;
import com.cy.detectsys.util.BaseResponseInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.io.File;
import java.util.List;

/**
* @author asus
* @description 针对表【net_pop】的数据库操作Service实现
* @createDate 2024-06-12 16:21:41
*/
@Service
public class NetPopServiceImpl extends ServiceImpl<NetPopMapper, NetPop>
    implements NetPopService{
    @Resource
    NetPopMapper netPopMapper;
    /**
     * @description: TODO
     * @author    pop列表
     * @date 2024/6/1 15:21
     * @version 1.0
     */
    @Override
    public BaseResponseInfo popList(PopVo popVo) {
        if (popVo.getPageNum() != null && popVo.getPageSize() != null) {
            PageHelper.startPage(popVo.getPageNum(), popVo.getPageSize());
        }

        QueryWrapper<NetPop> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(popVo.getFacilityname())){
            wrapper.eq("facilityName",popVo.getFacilityname());
        }
        if (StringUtils.isNotEmpty(popVo.getBuildtype())){
            wrapper.eq("buildType",popVo.getBuildtype());
        }
        if (StringUtils.isNotEmpty(popVo.getCity())){
            wrapper.eq("city",popVo.getCity());
        }

        List<NetPop> list = list(wrapper); // 列表

        PageInfo<NetPop> dataCenterInfoPageInfo = new PageInfo<>(list);
        BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
        baseResponseInfo.data = dataCenterInfoPageInfo;
        baseResponseInfo.setCode(200);
        baseResponseInfo.setMsg("成功");
        return baseResponseInfo;
//
//        PageHelper.startPage(popVo.getPageNum(), popVo.getPageSize());
//        List<NetPop> list = list();
//        PageInfo<NetPop> dataCenterInfoPageInfo = new PageInfo<>(list);
//        BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
//        baseResponseInfo.data = dataCenterInfoPageInfo;
//        baseResponseInfo.setCode(200);
//        baseResponseInfo.setMsg("成功");
//        return baseResponseInfo;
    }

    @Override
    public BaseResponseInfo popJsonList() {
        return null;
    }

//    @Override
//    public BaseResponseInfo popJsonList() {
//        File file = new File("D:\\sj\\pop\\pop.json");
//        String json =JsonUtil.FileToString(file);
//        JSONArray jsonArray = JSON.parseArray(json);
//
//        for (int i = 0; i < jsonArray.size(); i++) {
//            JSONObject jsonObject = jsonArray.getJSONObject(i);
//
//            // 从 JSONObject 中获取需要的数据
//            String id = jsonObject.getString("id");
//            String buildType = jsonObject.getString("buildType");
//            String facilityName = jsonObject.getString("facilityName");
//            String city = jsonObject.getString("city");
//            String geographyId = jsonObject.getString("geographyId");
//            String regionIds = jsonObject.getString("regionIds");
//            String countryName = jsonObject.getString("countryName");
//            String latitude = jsonObject.getString("latitude");
//            String longitude = jsonObject.getString("longitude");
//            String operationalTaxonomyName = jsonObject.getString("operationalTaxonomyName");
//            String phaseName = jsonObject.getString("phaseName");
//            String facilityTypeName = jsonObject.getString("facilityTypeName");
//            String campusName = jsonObject.getString("campusName");
//            String facilityOwner = jsonObject.getString("facilityOwner");
//
//            NetPop netPop = new NetPop();
//            netPop.setId(id);
//            netPop.setBuildtype(buildType);
//            netPop.setFacilityname(facilityName);
//            netPop.setCity(city);
//            netPop.setGeographyid(geographyId);
//            netPop.setRegionids(regionIds);
//            netPop.setCountryname(countryName);
//            netPop.setLatitude(latitude);
//            netPop.setLongitude(longitude);
//            netPop.setOperationaltaxonomyname(operationalTaxonomyName);
//            netPop.setPhasename(phaseName);
//            netPop.setFacilityname(facilityTypeName);
//            netPop.setCampusname(campusName);
//            netPop.setFacilityowner(facilityOwner);
//            save(netPop);
//        }
//
//        return null;
//    }

    @Override
    public BaseResponseInfo popById(PopVo popVo) {
        NetPop netPop = netPopMapper.selectById(popVo.getId());
        BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
        baseResponseInfo.data = netPop;
        baseResponseInfo.setCode(200);
        baseResponseInfo.setMsg("成功");
        return baseResponseInfo;
    }

    @Override
    public BaseResponseInfo getPopList() {
        List<NetPop> list = list();
        BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
        baseResponseInfo.data = list;
        baseResponseInfo.setCode(200);
        baseResponseInfo.setMsg("成功");
        return baseResponseInfo;
    }

    @Override
    public BaseResponseInfo popBox() {
        QueryWrapper<NetPop> wrapper = new QueryWrapper<>();
        wrapper.select("DISTINCT facilityName");
        List<NetPop> facilityNameList = netPopMapper.selectList(wrapper);


        wrapper.select("DISTINCT buildType");
        List<NetPop> buildTypeList = netPopMapper.selectList(wrapper);
        PopResponse response = new PopResponse();
        response.setFacilityNameList(facilityNameList);
        response.setBuildTypeList(buildTypeList);

        BaseResponseInfo baseResponseInfo = new BaseResponseInfo();

        baseResponseInfo.data = response;
        baseResponseInfo.setCode(200);
        baseResponseInfo.setMsg("成功");

        return baseResponseInfo;
    }

}




